import time
from math import log10

st = time.clock()

max_sum = 1
for i in range(99,90,-1):
    for j in range(99,90,-1):
        str_mul = str(i ** j)
        if len(str_mul)<max_sum/9:
        # if round(j*log10(i))+1<max_sum/9:
            continue
        else:

            sum_mul = sum([int(num) for num in list(str_mul)])
            if sum_mul>max_sum:
                max_sum = sum_mul

print(max_sum)
print(time.clock()-st)


st = time.clock()
from itertools import permutations
x = range(1, 101)
per_2_x = permutations(x, 2)
f = lambda x,y: sum([int(k) for k in str(x**y)])
print(max([f(x[0],x[1]) for x in per_2_x]))
print(time.clock()-st)